home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / unity320.zip / FERROR.PAS < prev    next >
Pascal/Delphi Source File  |  1991-06-14  |  8KB  |  280 lines

  1. Program FindPasOrAsmError;
  2.  
  3. Uses
  4.   Dos;
  5.  
  6. { Error message filter.  This version supports the following:           }
  7. {                                                                       }
  8. {       Turbo Pascal                                                    }
  9. {       Turbo Assembler                                                 }
  10. {       Turbo C++                                                       }
  11. {       Turbo Link                                                      }
  12. {       Microsoft Macro Assembler 5.1                                   }
  13. {       QuikByte Pascal & Linker                                        }
  14. {        and possibly all Microsoft command line compilers              }
  15.  
  16. { The output MUST go to the standard output device.  If the CRT unit is }
  17. { used the output will go directly to the screen or through the BIOS,   }
  18. { and not to the standard output.  XP will not be able to locate the    }
  19. { error messages if that occures.                                       }
  20.  
  21. Var
  22.   Source : Text;
  23.   Line   : String;
  24.   Index  : Integer;
  25.   FileName : String;
  26.   LineNo   : String;
  27.   Column   : Integer;
  28.   Message  : String;
  29.   Buffer   : Array[1..1024] of Char;
  30.   Done     : Boolean;
  31.  
  32. Function Trim(Line : String) : String;
  33.  
  34. Begin
  35.   While (Line[1] = ' ') AND (Length(Line) > 0) Do Delete(Line,1,1);
  36.   While Line[Length(Line)] = ' ' Do Dec(Line[0]);
  37.   Trim := Line;
  38. End;
  39.  
  40. Procedure TurboPasFile;
  41.  
  42. Const
  43.   ErrorStr = 'Error';
  44.  
  45. Begin
  46.   Repeat
  47.     ReadLn(Source,Line);
  48.     Index := Pos(^M,Line);
  49.     While Index > 0 Do
  50.     Begin
  51.       Delete(Line,1,Index);
  52.       Index := Pos(^M,Line);
  53.     End;
  54.     Index := Pos(ErrorStr,Line);
  55.   Until (Index <> 0) OR Eof(Source);
  56.   If Index <> 0 THEN
  57.   BEGIN
  58.     Index := Pos('(',Line);
  59.     If (Index = 0) or (Index > Pos(ErrorStr,Line))
  60.       Then Writeln(', 0, 0, ',Line)
  61.     Else Begin
  62.       FileName := Copy(Line,1,Pred(Index));
  63.       Delete(Line,1,Index);
  64.       Index := Pos(')',Line);
  65.       LineNo := Copy(Line,1,Pred(Index));
  66.       Delete(Line,1,Index+2);
  67.       Message := Line;
  68.       ReadLn(Source,Line);
  69.       ReadLn(Source,Line);
  70.       Column := Pos('^',Line);
  71.       WriteLn(FileName,',',LineNo,',',Column,',',Message);
  72.     End;
  73.   END;
  74. End;
  75.  
  76. Procedure TurboAsmFile;
  77.  
  78. Const
  79.   Errors : Array[1..3] of String[9] = ('**Error**','*Warning*','**Fatal**');
  80.  
  81. Var
  82.   Loop : Integer;
  83.   Temp : String;
  84.  
  85. Begin
  86.   While Not Eof(Source) Do
  87.   Begin
  88.     Repeat
  89.       ReadLn(Source,Line);
  90.       Index := Pos(^M,Line);
  91.       While Index > 0 Do
  92.       Begin
  93.         Delete(Line,1,Index);
  94.         Index := Pos(^M,Line);
  95.       End;
  96.       Loop := 1;
  97.       Repeat
  98.         Index := Pos(Errors[Loop],Line);
  99.         If Index = 0
  100.           Then Inc(Loop)
  101.         Else Begin
  102.           Temp := Copy(Line,1,Length(Errors[Loop]));
  103.           If Index > 1 Then Delete(Temp,1,Pred(Index));
  104.           Delete(Line,1,Succ(Length(Errors[Loop])));
  105.           Loop := 4;
  106.         End;
  107.       Until (Loop > 3) Or Eof(Source);
  108.     Until (Index <> 0) OR Eof(Source);
  109.     If Index <> 0 THEN
  110.     BEGIN
  111.       Index := Pos('(',Line);
  112.       If Index = 0
  113.         Then Begin
  114.           FileName := '';
  115.           LineNo := '0';
  116.           Column := 0;
  117.           Message := Trim(Line);
  118.         End
  119.       Else Begin
  120.         FileName := Copy(Line,1,Pred(Index));
  121.         Delete(Line,1,Index);
  122.         Index := Pos(')',Line);
  123.         LineNo := Copy(Line,1,Pred(Index));
  124.         Delete(Line,1,Succ(Index));
  125.         Message := Line;
  126.         Column := 0;
  127.       End;
  128.       WriteLn(FileName,',',LineNo,',',Column,',',Temp,' ',Message);
  129.     End;
  130.   END;
  131. End;
  132.  
  133. Procedure QuickBytePascal;
  134.  
  135. Begin
  136.   Line := '';
  137.   While (Not Eof(Source)) AND (Pos('QBPERR.EXE',Line) = 0) Do ReadLn(Source,Line);
  138.   If Eof(Source) Then Halt;
  139.   While Not Eof(Source) Do
  140.   Begin
  141.     ReadLn(Source,LIne);
  142.     If Pos('):',Line) > 0 Then
  143.     Begin
  144.       Index := Pos('(',Line);
  145.       Message := Copy(Line,1,Pred(Index)) + ', ';
  146.       Delete(Line,1,Index);
  147.       Index := Pos(')',Line);
  148.       Message := Message + Copy(Line,1,Pred(Index)) + ', 1, ';
  149.       Delete(Line,1,Index + 2);
  150.       WriteLn(Message,Line);
  151.     End;
  152.   End;
  153. End;
  154.  
  155. Procedure Microsoft;
  156.  
  157. Begin
  158.   While Not Eof(Source) Do
  159.   Begin
  160.     ReadLn(Source,Line);
  161.     If Pos('LINK :',Line) = 1
  162.       Then WriteLn(',0,0,',Line)
  163.     Else If Pos('):',Line) > 0 Then
  164.     Begin
  165.       Index := Pos('(',Line);
  166.       Message := Copy(Line,1,Pred(Index)) + ', ';
  167.       Delete(Line,1,Index);
  168.       Index := Pos(')',Line);
  169.       Message := Message + Copy(Line,1,Pred(Index)) + ', 1, ';
  170.       Delete(Line,1,Index + 2);
  171.       WriteLn(Message,Line);
  172.     End;
  173.   End;
  174. End;
  175.  
  176. Procedure TurboLink;
  177.  
  178. Var
  179.   Temp : String;
  180.  
  181. Const
  182.   Errors  : Array[1..3] of String[8] = ('Error:','Fatal:','Warning:');
  183.  
  184. Begin
  185.   While Not Eof(Source) Do
  186.   Begin
  187.     ReadLn(Source,Line);
  188.     Index := 0;
  189.     Repeat
  190.       Inc(Index);
  191.     Until (Pos(Errors[Index],Line) <> 0) Or (Index > 3);
  192.     If Index <= 3 Then WriteLn(' , 0, 0, ',Line);
  193.   End;
  194. End;
  195.  
  196. Procedure TurboC_PlusPlus;
  197.  
  198. Const
  199.   MaxErrMsg = 2;
  200.   Errors  : Array[1..MaxErrMsg] of String[7] = ('Error','Warning');
  201.   NewError: Array[1..MaxErrMsg] of String[9] = ('**Error**','*Warning*');
  202.  
  203. Var
  204.   Index, Loop : Integer;
  205.   Temp : String;
  206.   IsError : Boolean;
  207.  
  208. Begin
  209.   While Not Eof(Source) Do
  210.     Begin
  211.       Repeat
  212.         ReadLn(Source,Line);
  213.         If Pos('Turbo Link',Line) = 1 Then
  214.         Begin
  215.           TurboLink;
  216.           Exit;
  217.         End;
  218.         Index := Pos(' ',Line);
  219.         Temp := Copy(Line,1,Index-1);
  220.         IsError := False;
  221.         Loop := 1;
  222.         While (Not IsError) AND (Loop <= MaxErrMsg) Do
  223.           If Temp = Errors[Loop] Then
  224.             IsError := True
  225.           Else
  226.             Inc(Loop);
  227.         If IsError Then
  228.           Begin
  229.             Delete(Line,1,Index);
  230.             Line := Trim(Line);
  231.             Index := Pos(' ',Line);
  232.             If Index > 0 Then
  233.             Begin
  234.               Temp := Copy(Line,1,Pred(Index)) + ', ';
  235.               Delete(Line,1,Index);
  236.               Index := Pos(':',Line);
  237.               Temp := Temp + Copy(Line,1,Pred(Index)) + ', 0, ';
  238.               Delete(Line,1,Index);
  239.               Writeln(Temp,Trim(Line));
  240.             End;
  241.           End;
  242.       Until Eof(Source);
  243.     End;
  244. End;
  245.  
  246. Begin
  247.   If ParamCount = 0 Then Halt;
  248.   Assign(Source,ParamStr(ParamCount));
  249.   SetTextBuf(Source,Buffer);
  250.   {$I-}
  251.   Reset(Source);
  252.   {$I-}
  253.   If IoResult <> 0 Then
  254.   Begin
  255.     WriteLn(', , , Error in FERROR when opening file!');
  256.     Halt(1);
  257.   End;
  258.   Repeat
  259.     Done := True;
  260.     ReadLn(Source,Line);
  261.     If Pos('Turbo Pascal',Line) <> 0             { Turbo Pascal       }
  262.       Then TurboPasFile
  263.     Else If Pos('Turbo Assembler',Line) <> 0     { Turbo Assembler    }
  264.       Then TurboAsmFile
  265.     Else If Pos('QuikByte Pascal',Line) <> 0     { Quick Byte Pascal  }
  266.       Then QuickBytePascal
  267.     Else If Pos('Macro Assembler',Line) <> 0     { Microsoft MASM     }
  268.       Then Microsoft
  269.     Else If Pos('Turbo C++',Line) <> 0           { Turbo C/C++        }
  270.       Then TurboC_PlusPlus
  271.     Else If Pos('Turbo Link',Line) <> 0          { Turbo Link         }
  272.       Then TurboLink
  273.     Else If Pos('Microsoft',Line) <> 0           { All Microsoft?     }
  274.       Then Microsoft
  275.     Else Done := False;
  276.   Until Done or Eof(Source);
  277.   If Not Done Then WriteLn(', , , Unrecognized compiler output!');
  278.   If TextRec(Source).Mode = FmInput Then Close(Source);
  279. End.
  280.